<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/taglibs.jsp"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ page import="com.yaodian100.core.common.utils.ServerValue"%>
<head>
	<style type="text/css">
	h1 span{visibility:visible;}
	td span{visibility:visible;}
	.msg{float:left; line-height:1em; margin:0; display:block;border:1px solid #f66;padding:2px 5px;*padding:2px 5px 1px;}
	.msg.rn{background-color:#fff2f2;border-color:#f66;}
	</style>
</head>

<c-rt:set var="midContextPath" value='<%=ServerValue.getMidContextPath() %>'/>
<c-rt:set var="frontHostname" value='<%=ServerValue.getFrontHostname() %>'/>
<%-- 数字验证 --%>
<script type="text/javascript" charset="UTF-8" src="/js/jquery.alphanumeric.js"></script>
<%-- 月历 --%>
<link rel="stylesheet" type="text/css" href="/css/smoothness.datepick.css" />
<script type="text/javascript" charset="UTF-8" src="/js/jquery.datepick.js"></script>
<script type="text/javascript" charset="UTF-8" src="/js/jquery.datepick-zh-CN.js"></script>
<script type="text/javascript" charset="UTF-8" src="/js/yaodian100.common.js"></script>
<script type="text/javascript" charset="UTF-8" src="/js/jquery.autotab-1.1b.js"></script>

<s:if test='%{"IDX_HOTSALE_V5".equals(advType)}'>
	<s:set name="searchLink" value='%{"/generate/idxV5/searchIdx.do"}' />
	<s:set name="advTypeTitle" value='%{"首页"}' />
</s:if>
<s:elseif test='%{"PCL_HOTSALE_V5".equals(advType)}'>
	<s:set name="searchLink" value='%{"/generate/idxV5/searchPcl.do"}' />
	<s:set name="advTypeTitle" value='%{"PCLady"}' />
</s:elseif>

<script>
	$().ready( function() {
		<%-- 日历绑定 --%>
		$('#startDate').datepick({minDate: new Date(), showOn:'both',numberOfMonths:2, buttonImageOnly: true, buttonImage: '/images/calendar.gif',dateFormat:"yy-mm-dd"}); 
		$('#endDate').datepick({minDate: new Date(),showOn: 'both',numberOfMonths:2, buttonImageOnly: true, buttonImage: '/images/calendar.gif',dateFormat:"yy-mm-dd"});
		
		$('input[id^=prodId]').each(function() {
			$('#' + this.id).onlyInteger();
			$(this).blur(function(){
				var no = this.id.substring(this.id.length - 1);
				$(this).val(prodPadLeft($(this).val()));
				getProductInfo3('${midContextPath}', 'prodName' + no, 'brief' + no, 'prodIsOk' + no, $(this).val());
			});
		});
		
		$('#subBtn').click(function() {
			if( validate_data() ) {
				$('#advStatus').val('10');
				$('#idxHotSaleForm').submit();
			}
		});

		$("#draftBtn").click(function(){
			if ( validate_data() ){
				$("#advStatus").val("00");
				$("#idxHotSaleForm").submit();
			}
		});
		
		$("#canBtn").click(function(){
			if ( validate_data() ){
				$("#advStatus").val("90");
				$("#idxHotSaleForm").submit();
			}
		});
		
		$('#bakBtn').click(function() {
			location.href = '${midContextPath}${searchLink}';
		});
		
		$('input[id^=adWord]').alphanumeric();
		$('input[id^=adWord]').autotab_filter({ format: 'custom', pattern: '[^a-zA-Z0-9]' });
	});
	
	function validate_data(){
		var isCorrect = true; <%-- 预设验证正确 --%>
		
		cleanTip();
		
		var prod_size = document.getElementsByName('prodId').length;
		for( var i = prod_size; i > 0 ; i-- ) {
			if( $('#prodName' + i).val() == '' ) {
				appendTip('prodName' + i, '请输入商品名称' + i, true);
				isCorrect = false;
			} else if( !vaildateLength(22, $('#prodName' + i).val()) ) {
				appendTip('prodName' + i, '商品名称最多22个中文，44个英文字母', true);
				isCorrect = false;
			}
			if( $('#brief' + i).val() == '' ) {
				appendTip('brief' + i, '请输入商品小标' + i, true);
				isCorrect = false;
			} else if( !vaildateLength(11, $('#brief' + i).val()) ) {
				appendTip('brief' + i, '商品小标最多11个中文，22个英文字母', true);
				isCorrect = false;
			}
			if( $('#prodIsOk' + i).val() == 'N' ) {
				appendTip('prodId' + i, '商品编号 ' + i + '错误', true);
				isCorrect = false;
			}
			if( $('#prodId' + i).val() == '' ) {
				appendTip('prodId' + i, '请输入商品编号' + i, true);
				isCorrect = false;
			}
		}
		
		if($('#startDate').val()>$('#endDate').val()) {
			appendTip('endDate', '结束日期不能小于起始日期', true);
			isCorrect = false;
		} else if($('#startDate').val()==$('#endDate').val()) {
			if($('#startTime').val()>=$('#endTime').val()){
				appendTip('endDate', '结束时间需大于起始时间', true);
				isCorrect = false;
			}
		}
		if( $("#endDate").val() == "" ) {
			appendTip('endDate', '请输入结束时间', true);
			isCorrect = false;
		}
		if( $('#startDate').val() == '') {
			appendTip('startDate', '请输入起始时间', true);
			isCorrect = false;
		}
		if( $('#advName').val() == '' ) {
			appendTip('advName', '请输入广告名称', true);
			isCorrect = false;
		}
		
		return isCorrect;
	}
	<%-- 清空提示 --%>
	function cleanTip() {
		$("span:[id^=Tip_]").hide();
		$("span:[id^=Tip_]").text('');
	}
	<%-- 附加提示 --%>
	function appendTip(id, msg, isFocus) {
		if( !(isFocus == true || isFocus == false) ) 
			isFocus = true;
		
		var target = $('#Tip_' + id);
		if(target.text().length > 0) {
			appendWord(target, msg);
		} else
			target.text(msg);
		target.show();
		if(isFocus)
			$('#' + id).focus();
	}
	
	function appendWord(origin, apptext){
		if(origin.text().length==0){
			origin.text(apptext);
		}else{
			origin.text(origin.text()+', '+apptext);
		}
	}
</script>
<s:if test="hasErrors()">
<p><s:actionerror cssClass="msg rn" /></p>
</s:if>
<s:if test="hasActionMessages()">
<p><s:actionmessage cssClass="msg rn" /></p>
</s:if>
<s:if test="hasFieldErrors()">
<p><s:fielderror cssClass="msg rn" /></p>
</s:if>
<h1>广告上架管理</h1>
<s:form action="idxHotSaleV5/saveIdxHotSale.do" method="post" name="idxHotSaleForm" id="idxHotSaleForm" >
	<table class="tb-data" width="100%">
		<tbody>
			<tr>
				<th>类型</th>
				<td>${advTypeTitle} - 热销商品V5<input type="hidden" name="advType" id="advType" value="${advType}"/></td>
			</tr>
				<th><span class="txt-red">*</span> 广告名称</th>
				<td><input type="text" id="advName" name="advName" value="${advName}" size="30" maxlength="30"/><br/><span id="Tip_advName" class="msg rn" style="display:none;"></span></td>
			</tr>
			<tr>
				<th><span class="txt-red">*</span> 起迄时间</th>
				<td>
				<input type="text" id="startDate" name="startDate" value="${startDate}" maxlength="10"/>
				<select id="startTime" name="startTime">			
					<c-rt:forEach begin="0" end="23" var="t1">
						<c-rt:if test="${t1<10}">
						<c-rt:set value="0${t1}:00" var="sTime"></c-rt:set>
						</c-rt:if>
						<c-rt:if test="${t1>=10}">
						<c-rt:set value="${t1}:00" var="sTime"></c-rt:set>
						</c-rt:if>
						<option value="${sTime}" <c-rt:if test="${sTime==startTime}">selected</c-rt:if>>${sTime}</option>
					</c-rt:forEach>
				</select> ~ 				 
				<input type="text" id="endDate" name="endDate" value="${endDate}" maxlength="10"/>
				<select id="endTime" name="endTime">
					<c-rt:forEach begin="0" end="23" var="t2" >
						<c-rt:set var="t3">${23-t2}</c-rt:set>	
						<c-rt:if test="${t3<10}">
						<c-rt:set value="0${t3}:59" var="eTime"></c-rt:set>
						</c-rt:if>
						<c-rt:if test="${t3>=10}">
						<c-rt:set value="${t3}:59" var="eTime"></c-rt:set>
						</c-rt:if>
						<option value="${eTime}" <c-rt:if test="${eTime==endTime }">selected</c-rt:if>>${eTime}</option>
					</c-rt:forEach>
				</select>
				<br/>
				<span id="Tip_startDate" class="msg rn" style="display:none;"></span><span id="Tip_startTime" class="msg rn" style="display:none;"></span><span id="Tip_endDate" class="msg rn" style="display:none;"></span><span id="Tip_endTime" class="msg rn" style="display:none;"></span>
				</td>
			</tr>
			<tr>
				<td colspan="2"><img src="/eventImg/IDX_HOTSALE_V5.jpg"></td>
			</tr>
			<tr>
				<td colspan="2">
					<table class="tb-data" >
					<c-rt:forEach var="no" begin="1" end="${AD_SIZE}" step="1">
						<c-rt:set var="c" value="${no%2}"/>
						<c-rt:if test="${c==1}"><tr></c-rt:if>
							<td>
								<div style="margin: 4px 0 6px 12px;">
									<ul>
										<li><span class="txt-red">*</span> 商品编号${no}</li>
										<li style="margin-bottom: 8px"><input type="hidden" id="prodIsOk${no}" value=""/>
											<div style="overflow: hidden;">
												<input type="text" id="prodId${no}" name="prodId" size="50" value="${prodId[no-1]}" >
												<br/><span id="Tip_prodId${no}" class="msg rn" style="display:none;"></span>
											</div>
										</li>
										<li><span class="txt-red">*</span> 商品小标</li>
										<li style="margin-bottom: 8px">
											<div style="overflow: hidden;">
												<input type="text" id="brief${no}" name="brief" size="50" maxlength="22" value="${brief[no-1]}" /><span class="txt-rd">11字內</span>
												<br/><span id="Tip_brief${no}" class="msg rn" style="display:none;"></span>
											</div>
										</li>
										<li><span class="txt-red">*</span> 商品名称</li>
										<li style="margin-bottom: 8px">
											<div style="overflow: hidden;">
												<input type="text" id="prodName${no}" name="prodName" size="50"  maxlength="44" value="${prodName[no-1]}" /><span class="txt-rd">22字內</span>
												<br/><span id="Tip_prodName${no}" class="msg rn" style="display:none;"></span>
											</div>
										</li>
										<li>广告代码（非必填。由英数字组成，最多25个半角）</li>
										<li>
											<input type="text" id="adWord${no}" name="adWord" size="50" maxlength="25" value="${adWord[no-1]}" />
										</li>
									</ul>
								</div>
							</td>
						<c-rt:if test="${c==0}"></tr></c-rt:if>
					</c-rt:forEach>
					</table>
				</td>
			</tr>
			<tr>
				<th>修改记录</th>
				<td>
					<p>建立：<fmt:formatDate value="${createDate}" pattern="yyyy-MM-dd HH:mm"/> / ${createUser}</p>
					<p>修改：<fmt:formatDate value="${modifyDate}" pattern="yyyy-MM-dd HH:mm"/> / ${modifyUser}</p>
				</td>
			</tr>
			<tr>
				<td colspan="2">
					<div style="float: right;">
						<input type="hidden" id="advId" name="advId" value="${advId}"/>
						<input type="hidden" id="advStatus" name="advStatus" value="${advStatus}"/>
						<input type="button" id="subBtn" name="subBtn" value="发送"/>
						<!-- <input type="button" id="draftBtn" name="draftBtn" value="草稿"/> -->
						<input type="button" id="canBtn" name="canBtn" value="暂停"/>
						<input type="button" id="bakBtn" name="bakBtn" value="回查询列表"/>
					</div>
				</td>
			</tr>
		</tbody>
	</table>
</s:form>